// pages/spotList/spotDetails/index.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    longitude: '87.60485',
    latitude: '43.8095',
    address:{},
    markers: [{
      iconPath: '../../../image/address-icon.png',
      // id: ele.id,
      longitude: '87.60485',
      latitude: '43.8095',
      width: 25,
      height: 25,
      // callout: {
      //     content: 'asdfasdf',
      //     padding: 5,
      //     color: "#000",
      //     borderRadius: 5,
      //     bgColor: "#fff",
      //     fontSize: '15',
      //     display:"BYCLICK"
      // },
    }]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let name = options.name
    wx.setNavigationBarTitle({
      title: name
    });
    this.loadLocationInfo(name)
  },
  loadLocationInfo(name){
    let _this = this
    let key = app.globalData.mapKey
    // console.log(`https://apis.map.qq.com/ws/place/v1/search?keyword=${name}&boundary=region(乌鲁木齐市,0,${_this.data.latitude,_this.data.longitude})&key=${key}`)
    wx.request({
      url: `https://apis.map.qq.com/ws/place/v1/search?keyword=红山公园&boundary=region(乌鲁木齐,0,${_this.data.latitude,_this.data.longitude})&filter=category=景点&key=${key}`,
      data: {},
      header: { 'content-type': 'application/json' },
      method: 'GET',
      dataType: 'json',
      success: (res) => {
        console.log(res.data.data) 
        _this.setData({
          address:res.data.data[0]
        })
        console.log(_this.data.address) 
      },
      fail: () => {
          wx.showToast({
              title: '请求失败！！！！',
              icon: 'fail',
              image: '',
              duration: 1500,
              success: (result) => {

              }
          });
      }
  });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})